import { del, get, post, put } from "@/common/http";
import { IDepartment } from "@/types/department";
import { IOrganization } from "@/types/organization";
import { IEmployee } from "../types/employee";
import { IQueryEmployeePageParams } from "../types/organization";
import { ITableWrap } from "../types/common";

/**
 *
 * @param data
 * @returns 创建组织架构 - 部门
 */
export const createDepartment = (data: Partial<IOrganization>) =>
  post("/api/v1/organization", data);

/**
 *
 * @param data
 * @returns 组织架构 - 单条查询
 */
export const organizationFindOne = (id: string) =>
  get<IOrganization>("/api/v1/organization/" + id);

/**
 *
 * @param data
 * @returns 树结构
 */
export const organizationTreeList = () =>
  get<IOrganization[]>("/api/v1/organization/tree");

/**
 *
 * @param data
 * @returns 员工分页
 */
export const organizationEmployeePage = (params: IQueryEmployeePageParams) =>
  get<ITableWrap<IEmployee>>("/api/v1/organization/employee/page", {
    params,
  });

/**
 *
 * @param data
 * @returns 员工添加
 */
export const organizationEmployeeSave = (data: Partial<IOrganization>) =>
  post<boolean>("/api/v1/organization/employee", data);
/**
 *
 * @param data
 * @returns 员工删除
 */
export const organizationEmployeeDelete = (ids: string) =>
  del<boolean>("/api/v1/organization/employee", {
    params: {
      ids,
    },
  });

/**
 *
 * @param data
 * @returns 选择部门下拉框
 */
export const organizationDepartmentList = () =>
  get<IDepartment[]>("/api/v1/organization/department/list");

/**
 *
 * @param id
 * @returns 删除组织
 */
export const organizationDelete = (id: string) =>
  del<boolean>("/api/v1/organization", { params: { id } });

/**
 *
 * @param id
 * @returns 置顶
 */
export const organizationToTop = (id: string) =>
  put<boolean>("/api/v1/organization/toTop", { id });

/**
 *
 * @param id
 * @returns 置底
 */
export const organizationToBottom = (id: string) =>
  put<boolean>("/api/v1/organization/toBottom", { id });

/**
 *
 * @param id
 * @returns 上移
 */
export const organizationMoveUp = (id: string) =>
  put<boolean>("/api/v1/organization/moveUp", { id });

/**
 *
 * @param id
 * @returns 下移
 */
export const organizationMoveDown = (id: string) =>
  put<boolean>("/api/v1/organization/moveDown", { id });
